﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace YXShop.Web.admin.systeminfo
{
    public partial class bank_list : System.Web.UI.Page
    {
        YXShop.BLL.SystemInfo.BankAccount bankBll = new YXShop.BLL.SystemInfo.BankAccount();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                YXShop.Common.PromptInfo.Popedom("010003001");
                InitWebControl();
                if (ChangeHope.WebPage.PageRequest.GetFormString("Option") != string.Empty && ChangeHope.WebPage.PageRequest.GetFormString("id") != "")
                {
                    YXShop.Common.PromptInfo.Popedom("010003003","对不起，您没有权限进行删除");
                    string types = Request["Option"].Trim();
                    string id = ChangeHope.WebPage.PageRequest.GetFormString("id");
                    if (types == "del")
                    {
                        if (YXShop.Common.PromptInfo.Message("010003003") != "ok")
                        {
                            bankBll.Delete(Convert.ToInt32(id));
                        }
                        else
                        {
                            Response.Write("no");
                        }
                    }
                    if (types == "delAll")
                    {
                          if (YXShop.Common.PromptInfo.Message("010003003") != "ok")
                        {
                        bankBll.DeleteAll(id);
                        }
                          else
                          {
                              Response.Write("no");
                          }
                    }
                    Response.End();
                    return;
                }
                this.litBank.Text = GetList();
            }

        }

        #region 获取TABLE
        //绑定table
        public string GetList()
        {
            ChangeHope.WebPage.Table table = new ChangeHope.WebPage.Table();
            ChangeHope.DataBase.DataByPage dataPage = bankBll.GetAllList();
            table.AddHeadCol("","选择");
            table.AddHeadCol("","Logo");
            table.AddHeadCol("","帐户名称");
            table.AddHeadCol("","开户行");
            table.AddHeadCol("","发布类型");
            table.AddHeadCol("","发布人");
            table.AddHeadCol("","帐户");
            table.AddHeadCol("","权重");
            table.AddHeadCol("","状态");
            table.AddHeadCol("","常规操作");
            table.AddRow();
            if(dataPage.DataReader!=null){
                while(dataPage.DataReader.Read()){
                    table.AddCol("<input id=\"cbTm\"  type=\"checkbox\" value=" + dataPage.DataReader["bank_id"] + " />");
                    table.AddCol("<img src='../../" + dataPage.DataReader["bank_icon"] + "' width=\"100\" height=\"48\"  />");
                    table.AddCol(dataPage.DataReader["bank_name"].ToString());
                    table.AddCol(dataPage.DataReader["bank_bankac"].ToString());
                    table.AddCol(GetName(dataPage.DataReader["bank_putouttypeid"]));
                    table.AddCol(PutMemberOut(dataPage.DataReader["bank_putouttypeid"], dataPage.DataReader["bank_putoutID"]));
                    table.AddCol(dataPage.DataReader["bank_account"].ToString());
                    table.AddCol(dataPage.DataReader["bank_ordernum"].ToString());
                    table.AddCol(dataPage.DataReader["bank_putout"].ToString()=="1"?"禁用":"默认");
                    table.AddCol("<a href='bank_edit.aspx?Bank_ID=" + dataPage.DataReader["bank_id"] + "'>编辑</a>  <a href=\"#\" onclick='Del(" + dataPage.DataReader["bank_id"] + ")'> 删除</a>");
                    table.AddRow();
                }
            }
            string view = table.GetTable() + dataPage.PageToolBar;
            dataPage.Dispose();
            dataPage = null;
            return view;
        }
        #endregion

        #region 发布类型
        //发布类型
        public string GetName(object objId)
        {
            string reStr = "管理员";
            if (objId != null)
            {
                int oid = Convert.ToInt32(objId);
                if (oid > 0)
                {
                    YXShop.BLL.Member.MemberRank meberBll = new YXShop.BLL.Member.MemberRank();
                    YXShop.Model.Member.MemberRank model = meberBll.GetModel(oid);
                    if (model != null)
                    {
                        reStr = model.Name;
                    }
                }
            }
            return reStr;
        }
        #endregion

        #region 管理员/商铺会员
        public string PutMemberOut(object typeId, object id)
        {
            string str = "";
            if (typeId != null && id != null)
            {
                if (Convert.ToInt32(typeId) == 0)
                {
                    YXShop.BLL.Admin.Administrators adminBll = new YXShop.BLL.Admin.Administrators();
                    YXShop.Model.Admin.Administrators adminModel = adminBll.GetModel(Convert.ToInt32(id));
                    if (adminModel!= null)
                    {
                        str = adminModel.Name;
                    }
                }
                else
                {
                    YXShop.BLL.Member.MemberAccount userBll = new YXShop.BLL.Member.MemberAccount();
                    YXShop.Model.Member.MemberAccount user = userBll.GetModel(Convert.ToInt32(id));
                    if (user!=null)
                    {
                        str = string.Format("<a href='#?Pro_ID={0}'>{1}</a>", id, user.UserId);
                    }
                }

            }

            return str;
        }
        #endregion

        #region 初始类型
        private void InitWebControl()
        {
            ChangeHope.WebPage.WebControl.SetDropDownList(this.w_l_bank_putouttypeid, "Id", "Name", "yxs_memberrank", true);
            this.w_l_bank_putouttypeid.Items.Add(new ListItem("管理员", "0"));
        }
        #endregion
        protected void btnOk_Click(object sender, EventArgs e)
        {
            this.litBank.Text = GetList();
        }
    }
}
